package com.playball.lottery.customview;

import java.io.File;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.playball.lottery.R;
import com.playball.lottery.util.AbstractActivity;
import com.playball.lottery.util.Constants;

/***
 * 对话框 activity
* @ClassName: CustomDilogActivity 
* @Description: TODO(这里用一句话描述这个类的作用) 
* @author vanszhen 
* @date 2014年7月16日 下午8:04:24 
*
 */
public class CustomDilogActivity extends AbstractActivity implements OnClickListener{

	//apk 名称
	private String apkName ;
	//img X
	private ImageView img_dele ;
	//btn 取消
	private Button btnCanclel;
	//btn 确定
	private Button btnOK;
	//btn mid
	private Button btnMid;
	//txt title
	private TextView txtTile ;
	// txt contant
	private TextView txtContent;
	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.jdd_coustom_dialog_layout);
		initView();
		initData();
	}
	
	private void initView() {
		
		img_dele = (ImageView) findViewById(R.id.img_dele_custom);
		img_dele.setOnClickListener(this);
		txtTile = (TextView) findViewById(R.id.title_custom);
		txtTile.setText("温馨提示");
		txtContent = (TextView) findViewById(R.id.message_custom);
		txtContent.setText("已在wifi下自动下载了最新版本，是否马上安装？");
		btnCanclel = (Button) findViewById(R.id.positiveButton_btn_custom);
		btnCanclel.setOnClickListener(this);
		btnMid= (Button) findViewById(R.id.neutralButton_btn_custom);
		btnMid.setVisibility(View.GONE);
		btnOK = (Button) findViewById(R.id.negativeButton_btn_custom);
		btnOK.setOnClickListener(this);
		
		
	}
	
	private void initData() {
		apkName = getIntent().getStringExtra("apkName");
	}

	

	private void updateAPK() {
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setDataAndType(
				Uri.fromFile(new File(Constants.APK_PATH+"/", apkName)),
				"application/vnd.android.package-archive");
		startActivity(intent);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.img_dele_custom:
			CustomDilogActivity.this.finish();
			break;
		case R.id.positiveButton_btn_custom:
			CustomDilogActivity.this.finish();
			break;
		case R.id.negativeButton_btn_custom:
			updateAPK();
			CustomDilogActivity.this.finish();
			break;
		default:
			break;
		}
	}
	
}
